package org.jeecg.modules.actBusi.service.impl;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.IActBizService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.actBusi.entity.ActBusi;
import org.jeecg.modules.actBusi.mapper.ActBusiMapper;
import org.jeecg.modules.actBusi.service.IActBusiService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Description: 业务流程记录
 * @Author: jeecg-boot
 * @Date:   2022-09-17
 * @Version: V1.0
 */
@Service
public class ActBusiServiceImpl extends ServiceImpl<ActBusiMapper, ActBusi> implements IActBusiService, IActBizService {
    public static final String BUSI_ID_KEY = "busiId";
    public static final String BUSI_TYPE_KEY = "busiType";
    @Override
    public String ActSave(JSONObject req) {
        String busiId = req.getString(BUSI_ID_KEY);
        String busiType = req.getString(BUSI_TYPE_KEY);
        if(StrUtil.isBlank(busiId) || StrUtil.isBlank(busiType)){
            throw new IllegalArgumentException("业务流程请求参数缺失");
        }
        ActBusi actBusi = new ActBusi();
        actBusi.setBusiId(busiId);
        actBusi.setBusiType(busiType);
        saveOrUpdate(actBusi);
        return actBusi.getId();
    }

    @Override
    public void addBusiData(Map<String, Object> data) {
        //TODO 根据业务需要调整流程参数
        IActBizService.super.addBusiData(data);
    }

    @Override
    public JSONObject getFormById(String id) {
        ActBusi actBusi = this.baseMapper.selectById(id);
        return JSONObject.parseObject(JSONObject.toJSON(actBusi).toString());
    }

    @Override
    public Result preCheck(HttpServletRequest request) {
        return IActBizService.super.preCheck(request);
    }

    @Override
    public void finishCallBack(String id) {
        IActBizService.super.finishCallBack(id);
    }

    @Override
    public void startCallBack(String id) {
        IActBizService.super.startCallBack(id);
    }

    @Override
    public void taskCompletCallBack(JSONObject task, JSONObject actBusiness) {
        IActBizService.super.taskCompletCallBack(task, actBusiness);
    }
}
